import { close, get, open } from '../_redis';

/**
 * 验证码是否正确
 * @param captcha 验证码
 * @param uk 用户标识，从cookie中获取
 */
export default async function check(captcha: string, uk: string) {
	if (!uk) {
		return false;
	}
	const client = open();
	try {
		if (captcha === undefined || captcha === 'undefined' || captcha === null) {
			return false;
		}
		// 获取raids中的数据，与输入的数据进行对比
		const res = await get(client, uk);
		return (captcha + '') === (res + '');
	} catch (e) {
		return false;
	} finally {
		close(client);
	}
}
